package com.hwl.demo10.service;

import java.util.ArrayList;

/**
 * 抽象通知者
 *
 * @author sentry
 * @since 2023-03-19
 */
public abstract class Subject {

    private final ArrayList<Observer> list = new ArrayList<>();
    protected String name;
    private String action;

    public Subject(String name) {
        this.name = name;
    }

    public void attach(Observer observer) {
        list.add(observer);
    }

    public void detach(Observer observer) {
        list.remove(observer);
    }

    public void notifyEmployee() {
        for (Observer item : list) {
            item.update();
        }
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getName() {
        return name;
    }
}
